package pe.bn.WSServiceHost.serHost.model;


import javax.xml.rpc.holders.StringHolder;
import pe.bn.WSServiceHost.serHost.interactive.WSConnect;
import org.apache.log4j.Logger;

public class WSConsolidarGarantia {

	private static Logger log = Logger.getLogger(WSConsultaIngreso.class.getName());
	
	private HeadRequest cabeceraRequest;
	private BodyConsolidarGarantia body;
	
	public WSConsolidarGarantia(HeadRequest cab,BodyConsolidarGarantia input) {
		super();
		cabeceraRequest = cab;
		body = input;
	}

	public int ConsolidarGarantiaHost(
			HeadRespose cabeceraRespose
			,BodyConsolidarGarantia outPut) throws Exception {
		
		String cadenaHost = new String();
		StringHolder cadResultHolder = new StringHolder();	
		String cadenaResult = "";
		WSConnect wsConnect  =  new WSConnect();
		cadenaHost = cabeceraRequest.toString() + body.toString() ;
		int result = 9999;
		result =  wsConnect.EjecutarTramaHost(cadenaHost,cadResultHolder);
		cadenaResult = cadResultHolder.value.trim();
		
		/*TODO: QUITAR*/
		int longitudHead = cabeceraRequest.LongitudTrama();
		int longitudresult =cadenaResult.length();
		
		if (longitudresult >= longitudHead){
			String HeadResult = cadenaResult.substring(0,longitudHead);
			cabeceraRespose.FillCabecera(HeadResult);
		}else{
			cabeceraRespose = null;
		};
		
		int longitudBody =  body.LongitudTrama();
		
		if ( longitudresult == longitudHead + longitudBody){
			String BodyResult = cadenaResult.substring(longitudHead,longitudresult);
			outPut.FillBoby(BodyResult);
		}else{
			outPut = null;
		};
		return result;
	}
	
	public HeadRequest getCabeceraRequest() {
		return cabeceraRequest;
	}
	public void setCabeceraRequest(HeadRequest cabeceraRequest) {
		this.cabeceraRequest = cabeceraRequest;
	}
	public BodyConsolidarGarantia getBody() {
		return body;
	}
	public void setBody(BodyConsolidarGarantia body) {
		this.body = body;
	}
}
